#include "textedit.h"
#include <QMessageBox>
#include <QDebug>
#include <QRegExp>
TextEdit::TextEdit(QWidget *parent)
    :QTextEdit(parent)
{
    m_ischecked = false;
}

bool TextEdit::isOkFormat(QString input)
{
    QRegExp *rx = new QRegExp("/^[a-fA-F0-9]|' '$/");
    return rx->exactMatch(input);
}

void TextEdit::keyPressEvent(QKeyEvent *e)
{
    if(m_ischecked){
        if(e->text().length()>1){
            e->ignore();
            return;
        }
         char ch = e->text().toLatin1().toHex().toInt(false,16);
        if((ch>='a'&& ch<='f')\
          || (ch>='A' && ch<='F')\
          || (ch>='0'&&ch<='9')\
          || ch==' '\
          || e->key()==Qt::Key_Backspace\
          || e->key()==Qt::Key_Space\
          || e->key()==Qt::Key_Shift)
        {
            QTextEdit::keyPressEvent(e);
        }
    }
    else{
        QTextEdit::keyPressEvent(e);
    }
}

